package com.ruoyi.listener.entity;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;


@Component
public class AliyunSmsSend {
    private Client client;
    @Value("${aliyun.sms.accessKeyId}")
    private String accessKeyId;
    @Value("${aliyun.sms.accessKeySecret}")
    private String accessKeySecret;
    @PostConstruct
    public void init() throws Exception {
        System.out.println("<<<11<<<"+accessKeyId+">>>>>>>");
        System.out.println("<<<11<<<"+accessKeySecret+">>>>>>>");
        Config config = new Config()
                .setAccessKeyId(accessKeyId)
                .setAccessKeySecret(accessKeySecret);
        config.endpoint = "dysmsapi.aliyuncs.com";
        this.client = new Client(config);
    }

    public SendSmsResponse sendSms(String phoneNumber, String signName, String templateCode, String templateParam) throws Exception {
        SendSmsRequest request = new SendSmsRequest()
                .setPhoneNumbers(phoneNumber)
                .setSignName(signName)
                .setTemplateCode(templateCode)
                .setTemplateParam(templateParam);
        return client.sendSms(request);
    }

    @Override
    public String toString() {
        return "AliyunSmsSend{" +
                "accessKeySecret='" + accessKeySecret + '\'' +
                ", accessKeyId='" + accessKeyId + '\'' +
                ", client=" + client +
                '}';
    }
}
   